Redshift INET_NTOA - amazon-redshift

It's pretty straight forward - I'm wondering if there's a function that will calculate IP address from a number, equivalent to INET_NTOA in mySQL.
I'm aware I can calculate it, but the question remains.

Nothing out of the box, but you can write your own UDF in Python for that if you want, if you really need a function, or a simple expression in a query.

Update: inet_ntoa is available in redshift

Related

Ms Access, unquoting Strings for use in SQL

I am using Ms Access as GUI and I am connectiong to PostgreSQL over ADO. I like to prevent SQL-Injection over user input.
I know there are prameterized Queries, but I don't get them to work so far. Anyway, my question is:
Is there a build in function to quote out user input or do I need to write my own function?
There is no built-in function for this, so would have to roll your own.
That said, save that time and read up on queries and parameters in ADO. It is not that difficult - no magic - and many good tutorials are to be found for the browsing.

Wanting to obfuscate data in database incrementally

I am looking to obfuscate data in a postgres database that is quite large and would like to be able to do it incrementally. What i was thinking, is that I could roll the char's of names forward or something like that, but, I would need a way to be able to tell if it has been applied to that "name" already? any ideas on this? If it could be done this way i.e is_changed(), it would be easy to replay on the difference each day.
I am pretty much wanting to find all first/last /mobile/emails in the db and change them but not into garbage. Also, some names are in jsonb columns just to make it more complicated ;)
Cheers
Basically, I have decided to do a text pg_dump and scripted a solution which modifies all relevant data with the same pattern. This allows the relationships to be maintained after the obfuscation has been done.
It is also much simpler and performant than sql + updates across a large dataset.
Still open to other ideas if anyone has a better one.
If you're not terribly concerned with how obfuscated the resulting text is, maybe one of the hashing functions included within postgres would suffice, such as md5 just for a simple example.
UPDATE person p SET p.name = MD5(p.name::text);
A possible actual implementation might involve using the pgcrypto module to encode your values, this would not be terribly efficient however.
https://www.postgresql.org/docs/9.6/static/pgcrypto.html
UPDATE person p SET p.name = crypt(p.name::text, gen_salt('test'));
But as I asked in the comment, what is the threat profile you're trying to guard against? Obfuscation might not be a great solution for mitigating the effects of a data breach.

CTE vs TVF Performance

Which performs better: common table expressions or table value functions? Im designing a process that I could use either and am unable to find any real data either way. Whatever route I choose would be executed via a SP and the data would ultimately update a table connected through a linked server (unfortunately there is no way around this). Insights appreciated.
This isn't really a performance question. You are comparing tuna fish and watermelons. A cte is an inline view that can be used by the next query only. A TVF is a complete unit of work that can function on it's own, unlike a cte. They both have their place and when used correctly are incredibly powerful tools.

How to avoid copy and paste in a single T-SQL statement

There is some new feature of SQL, I think that it was intruduced in 2005 that I never used. I can't remember what it was called, but I recall reading about it. It was an acronym similar to CT_ or something....
It was used to avoid reproducing the same code within a single SQL, for readability and (I assume) for performance reasons--because the common code would only be evaluated once.
What was it called? I am having a bit of trouble trying to find it and thought someone could easily tell me.
You're talking about a Common Table Expression or CTE. It's especially useful for recursive queries.

PostgreSQL: How to force db use the "quicksort" sorting method instead of "top-N heapsort"?

Actually, all my question is written in subj-field. It's it somehow possible in PostgreSQL? Probably at server-config level, or can be configured in query, or in properties of table?
I hardly tried to google for it, but got no result. So your help would be very appreciated (even pointing me to google with correct query, if i'm mistaken.
Thanks beforehand.
You cannot. The planner will pick the more appropriate method based on what you're doing:
top-n sort if you've an order by / limit with a reasonably small number;
quick sort (in memory or on disk) if not.