Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to work in streaming mode #333

Open
bogdan opened this issue Mar 5, 2024 · 4 comments
Open

Ability to work in streaming mode #333

bogdan opened this issue Mar 5, 2024 · 4 comments

Comments

@bogdan
Copy link

bogdan commented Mar 5, 2024

The binary always waits for the STDIN to be closed and than formats all supplied sql:

$  pg_format -
select * from companies;
select * from companies;
Ctrl+D
SELECT
    *
FROM
    companies;

SELECT
    *
FROM
    companies;

This restricts the ability to work in streaming mode.
Is it possible to format one SQL statement as long as it finishes (e.g. by ;)?
cat can be used as example as it triggers output on each line break

@darold
Copy link
Owner

darold commented Mar 6, 2024

Hi,

If you want to format a query in interactive mode you must use the following:

echo "select * from companies;" | pg_format -

and call pg_format - each time you want to format e new query.

I agree that this is not convenient for streaming mode. I will see if there is a simple way to allow that.

@darold
Copy link
Owner

darold commented Mar 6, 2024

This could be handled using the Perl module Term::ReadLine but I'm not sure it could be helpful to have such feature. What is your use case for this feature?

@bogdan
Copy link
Author

bogdan commented Mar 6, 2024

I am calling pg_format executive from ruby program. It takes ~200ms to do, which is way too slow. If I can keep a running process in memory and interact with it through stdin and stdout (which what any programming language probably allows), the indent can be much faster.

@Profpatsch
Copy link

Maybe use the Record Separator ASCII/Unicode symbol? It’s 0x1E in Utf-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants